var treeGridIndex = {
    init: function () {//初始化
        var gridBodyId = $.getUrlParam('gridBodyId');
        var fbAndStr = $.getUrlParam('fbAnd');
        var fbStr = $.getUrlParam('fb');
        if (gridBodyId != undefined && gridBodyId != null && gridBodyId != "") {
            var gridId = "";
            var rowButtonType = "";/** 行按钮【1:URL,2:本地JSON,3:外站URL,4:自定义JSON】 */
            var topButtonType = "";/** 顶部按钮【1:URL,2:本地JSON,3:外站URL,4:自定义JSON】 */
            var rowButton = "";/** 行按钮 */
            var topButton = "";/** 顶部按钮 */
            var option = kaValue.getUrl("getGrid");
            option.url = option.url + "/" + gridBodyId;
            option.success = function (re) {
                if (re.code == 200) {
                    gridId = re.grids.id;
                    rowButtonType = re.grids.rowButtonType;
                    topButtonType = re.grids.topButtonType;
                    rowButton = re.grids.rowButton;
                    topButton = re.grids.topButton;
                } else {
                    setTimeout(function () {
                        kaMsg.error(re);
                        top.$(".kaTabMenu").find(".layui-this").each(function(){
                            $(this).find(".layui-tab-close").trigger("click");
                        });
                    }, 500);
                }
            }
            ka.ajax(option);
            if(gridId != undefined && gridId != null && gridId != ""){
                var fbAnd = false;
                if(fbAndStr != undefined && fbAndStr != null && fbAndStr != "" && fbAndStr == "1"){
                    fbAnd = true;
                } 
                var fb = true;
                if(fbStr != undefined && fbStr != null && fbStr != "" && fbStr == "0"){
                    fb = false;
                }
                var fsv = {};
                var option = kaValue.getUrl("getInitSort");
                option.url = option.url + "?gridId=" + gridId;
                option.success = function (re) {
                    if (re.code == 200) {
                        fsv = re.data;
                    }
                }
                ka.ajax(option);
                //默认查询字段
                var fv = [];
                var option = kaValue.getUrl("getInitQuery");
                option.url = option.url + "?gridId=" + gridId;
                option.success = function (re) {
                    if (re.code == 200) {
                        fv = re.data;
                    }
                }
                ka.ajax(option);
                var gidBody = {
                    id: gridBodyId,
                    kaposition: "1003",
                    fbAnd: fbAnd,
                    fb: fb,
                    fsv: fsv,
                    topbutton: {
                        type: topButtonType, //【1:URL,2:本地JSON,3:外站URL,4:自定义JSON】
                        datajson: topButton
                    },
                    button: {
                        type: rowButtonType, //【1:URL,2:本地JSON,3:外站URL,4:自定义JSON】
                        datajson: rowButton
                    },
                    fv: fv,//查询条件
                    column: []
                };
                var gridDivHtml = treegrid.getHtml(gidBody);
                $("#treeGridDivHtml_content").html(gridDivHtml);
                treegrid.loading(gidBody);
                //加载水印
                ka.watermark('#gridDivHtml_content');
            }
        } else {
            kaMsg.error({ "code": "500", "msg": "无效的路径！" });
            top.$(".kaTabMenu").find(".layui-this").each(function () {
                $(this).find(".layui-tab-close").trigger("click");
            });
        }
    }
}